<template>
	<view class="baseView" id="baseView">
		<index v-if="curPage=='index'"></index>
		<!-- <xuanke v-if="curPage=='xuanke'"></xuanke> -->
		<my v-if="curPage=='my'"></my>
		<ADTabbar :tabHeight='tabHeight' class="tabPt">
			<ADTabbarItem text="首页" dataCur="index" class="maxWidth" @click="navClick" :textColor="curPage=='index'? '#5fba9b':'#000'"
			 :icon="'../.././static/image/index' + [curPage=='index'?'-hover':''] + '.png'"></ADTabbarItem>
			<ADTabbarItem text="我的" dataCur="my" class="maxWidth" @click="navClick" :textColor="curPage=='my'? '#5fba9b':'#000'"
			 :icon="'../.././static/image/my' + [curPage=='my'?'-hover':''] + '.png'"></ADTabbarItem>
		</ADTabbar>
		
	</view>
</template>
<script>
	import ADTabbar from '../../components/andy-ADTabbar/ADTabbar.vue';
	import ADTabbarItem from '../../components/andy-ADTabbar/ADTabbarItem.vue';
	import AppConfig from '../../commom/appConfig.js';
	export default {
		components: {
			ADTabbar,
			ADTabbarItem
		},
		data() {
			return {
				curPage: 'index',
				tabHeight: AppConfig.TabbarHeight,
				// 为了接受子页面点击tabbar，传来的参数与之作比较
				pageParmas: {
					my: 'my',
				},
			}
		},
		onLoad(options) {
			// 接受子页面点击'我的'栏目传给主页参数,启用‘我的’页面
			// if (this.pageParmas.my === options.my) {
			// 	this.curPage = options.my 
		 //     } else if (this.pageParmas.xuanke === options.xuanke) {
			// this.curPage = options.xuanke
		 //    }
	},
	methods: {
		// 导航栏切换
		navClick: function(e) {
			this.curPage = e.currentTarget.dataset.cur;
			console.log(this.curPage)
		},
		// // 中间按钮点击
		// middleClick: function(e) {
		// 	uni.navigateTo({
		// 	    url: 'page5',
		// 	    animationType: 'slide-in-bottom',
		// 	    animationDuration: 200
		// 	});
		// }
    takeHanle() {
		uni.getSetting({
		   withSubscriptions: true,   //  这里设置为true,下面才会返回mainSwitch
		   success: function(res){   
		   
		     // 调起授权界面弹窗
		     if (res.subscriptionsSetting.mainSwitch) {  // 用户打开了订阅消息总开关
		       if (res.subscriptionsSetting.itemSettings != null) {   // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
		         let moIdState = res.subscriptionsSetting.itemSettings["qU8NS5ggFFoUQ3Jj_m9S7EtCDsEl0ChEWz7Enr73S0o","9nJmHjU4yaUt4rYjXPfFVQfZ-JJ-QCp00IXQ7r8bnF8"];  // 用户同意的消息模板id
		         if(moIdState === 'accept'){   
		           console.log('接受了消息推送');
		
		         }else if(moIdState === 'reject'){
		           console.log("拒绝消息推送");
		
		         }else if(moIdState === 'ban'){
		           console.log("已被后台封禁");
		
		         }
		       }else {
		         // 当用户没有点击 ’总是保持以上选择，不再询问‘  按钮。那每次执到这都会拉起授权弹窗
		         uni.showModal({
		           title: '提示',
		           content:'请授权开通服务通知',
		           showCancel: true,
		           success: function (ress) {
		             if (ress.confirm) {  
		               wx.requestSubscribeMessage({   // 调起消息订阅界面
		                 tmplIds: ["qU8NS5ggFFoUQ3Jj_m9S7EtCDsEl0ChEWz7Enr73S0o",'9nJmHjU4yaUt4rYjXPfFVQfZ-JJ-QCp00IXQ7r8bnF8'],
		                 success (res) { 
		                   console.log('订阅消息 成功 ');
		                   console.log(res);
							uni.setStorageSync('take', true);
		                 },
		                 fail (er){
		                   console.log("订阅消息 失败 ");
		                   console.log(er);
		                 }
		               })     
		                     
		             }
		           }
		         })
		       }
		
		     }else {
		       console.log('订阅消息未开启')
		     }      
		   },
		   fail: function(error){
		     console.log(error);
		   },
		 })
	}
	},
	mounted() {
	// uni.openSetting({
	//   success(res) {
	//     console.log(res.authSetting)
	//   },
	//   fail(res) {
	// 	   console.log('openSetting 失败')
	//   }
	// });
	
// 判断用户是否授权通知
		this.takeHanle();
	}
	}
</script>

<style>
	.middleItem {
		min-width: calc(100vw / 5);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 22upx;
	}

	.buttonView {
		width: 100upx;
		height: 100upx;
		border-radius: 50upx;
		margin-top: -60upx;
		background-color: #349E40;
		margin-bottom: 10upx;

		color: #FFFFFF;
		line-height: 100upx;
		text-align: center;
		font-size: 50upx;
	}

</style>
